<template>
  <!--任务处理-->
  <Card style="height:800px">
    <div>已处理</div>
    <div style="text-align:center;width:50%;margin:100px auto;" v-if="isShowPop==1">
      <Page :total="totalWD" :current="currentPageWD" :page-size="pageSizeWD" show-elevator show-total @on-change="handlePageChangeWD"></Page>
    </div>
    <!-- 处理中 -->
    <Form ref="search" inline>
      <FormItem>
        <Date-picker type="date" placeholder="创建时间（起）" v-model="startEndDate" format="yyyy-MM-dd"></Date-picker>
      </FormItem>
      <FormItem>
        <Date-picker type="date" placeholder="创建时间（止）" v-model="endEndDate" format="yyyy-MM-dd"></Date-picker>
      </FormItem>
      <FormItem>
        <Button type="primary" size="small" @click="query_processed">查询</Button>
      </FormItem>
    </Form>
    <Content style="margin-top:20px;" v-if="isShowPop==2">
      <Table border :columns="case_table_columns" :data="case_table_datas"></Table>
    </Content>
    <div style="text-align:center;width:50%;margin:100px auto;" v-if="isShowPop==2">
      <Page :total="total" :current="currentPage" :page-size="pageSize" size="small" show-elevator show-sizer show-total @on-change="handlePageChange"></Page>
    </div>
    <Button style="margin-left: 1450px;" type="primary" @click="handleGoBack">返回</Button>
  </Card>
</template>

<script>
export default {
  data () {
    return {
      isShowPop: 2,
      decision: 0,
      waiting: 1,
      processing: 0, // 处理中
      patch: 0, // 退回补件
      processed: 0, // 已处理
      isShowTab: 1,
      startEndDate: null,
      endEndDate: null,
      waitDecisionTableData: [],
      totalWD: 0,
      currentPageWD: 0,
      pageSizeWD: 20,
      case_table_columns: [{
        title: '客户姓名',
        key: 'custName',
        render: (h, params) => {
          const vm = this
          return h('div', {
            on: {
              click () {
                vm.$router.push({
                  name: 'task_detail',
                  query: {
                    loanId: params.row.loanId,
                    type: 1
                  }
                })
              }
            },
            style: {
              'color': '#20a0ff',
              'cursor': 'pointer'
            }
          }, params.row.custName)
        }
      },
      {
        title: '身份证',
        key: 'custCardNo'
      },
      {
        title: '当前环节',
        key: 'curNodeName'
      },
      {
        title: '处理环节',
        key: 'nodeName'
      },
      {
        title: '进件号',
        key: 'loanId'
      },
      {
        title: '产品',
        key: 'productTypeName'
      },
      {
        title: '处理时间',
        key: 'endTime',
        render: (h, params) => {
          var vm = this
          return h('div', [
            h('span', vm.$util.loanModularFormatTime(params.row.endTime))
          ])
        }
      },
      {
        title: '处理结果',
        key: 'cljg'
      }
      ],
      case_table_datas: [],
      total: 100,
      currentPage: 1,
      pageSize: 20
    }
  },
  methods: {
    // 返回上一页
    handleGoBack () {
      this.$router.back()
    },
    // 查询已处理单
    query_processed (goPage) {
      this.isShowTab = 1
      var params = {}
      if (parseFloat(goPage).toString() === 'NaN') {
        goPage = 1
      }
      params.pageNum = goPage
      if ((this.startEndDate !== '')) {
        params.startEndDate = this.startEndDate
      }
      if ((this.endEndDate !== '')) {
        params.endEndDate = this.endEndDate
      }
      let queryNodes = []
      queryNodes.push('woChecking')
      queryNodes.push('woApproval')
      queryNodes.push('woSampling')
      params.queryNodes = queryNodes
      this.$ajax.post(this.$appContext.marvels_core_approve + 'approve/process/service/query_processed', params).then(re => {
        if (re.data.code === 'success') {
          this.total = re.data.data.total
          this.pageSize = re.data.data.pageSize
          this.currentPage = re.data.data.pageNum
          this.case_table_datas = []
          var datas = re.data.data.list || []
          var list = this.$util.cloneObject(datas)
          list.forEach(item => {
            if (item.caseResult === 'OK') {
              item.cljg = '审核通过'
            } else if (item.caseResult === 'RETURN') {
              item.cljg = '审核退回'
            } else if (item.caseResult === 'REFUSE') {
              item.cljg = '审核拒绝'
            } else if (item.caseResult === 'REFUSE') {
              item.cljg = '审核退回到前端'
            }
            this.case_table_datas = list
          })
        } else {
          this.$Message.warning({
            title: '提示',
            content: '333' + re.data.data
          })
        }
      }).catch(er => {

      })
    },

    handleDecsionData () {
      var params = {}
      this.$ajax.post(this.$appContext.marvels_core_approve + 'approve/loan/service/runDecision', params).then(re => {
        if (re.data.code === 'success') {
          this.$Message.success({
            title: '提示',
            content: '本次处理' + re.data.data + '笔贷款!',
            onOk () { }
          })
        } else {
          this.$Message.warning({
            title: '提示',
            content: '内容：' + re.data.message,
            onOk () { }
          })
        }
      }).catch(er => {

      })
    },
    waitDecision (goPage) {
      this.isShowTab = 2
      var length = this.waitDecisionTableData.length
      // 没有加载过则加载数据
      if (length === 0) {
        var params = {}
        if (parseFloat(goPage).toString() === 'NaN') {
          goPage = 1
        }
        params.pageNum = goPage
        params.status = 'J00'
        this.$ajax.post(this.$appContext.marvels_core_approve + 'approve/loan/service/wdList', params).then(re => {
          // console.log(re.data);
          if (re.data.code === 'success') {
            this.totalWD = re.data.data.total
            this.pageSizeWD = re.data.data.pageSize
            this.currentPageWD = re.data.pageNum
            this.waitDecisionTableData = []
            var datas = re.data.data.list || []
            datas.forEach(item => {
              var tData = {}
              tData.name = item.custName
              tData.icNum = item.custCardNo
              tData.loanId = item.loanId
              if (item.applyTime != null) {
                tData.createTime = this.$util.formatTime(new Date(item.applyTime))
              }
              this.waitDecisionTableData.push(tData)
            })
          } else {
            this.$Message.warning({
              title: '提示',
              content: '22' + re.data.data,
              onOk () { }
            })
          }
        }).catch(er => {

        })
      }
    },
    handleTabClick (name) {
      this.activeTabName = name
    },
    handlePageChangeWD (index) {
      waitDecision(index)
    },
    handlePageChange (index) {
      this.query_processed(index)
    }
  },

  created () {
    this.$ajax = this.$util.ajax()
    this.query_processed()
  }
}
</script>

<style lang="less">
.header_div {
  width: 100%;
  padding: 0px 0px 0px 100px;
}

.header_div .item {
  margin: 20px 5px 0px 10px;
  width: 130px;
  float: left;
}

.header_div .div_bt {
  margin: 20px 100px 0px 10px;
  float: right;
}
</style>
